<?php

class FormEditBox extends FormControl {

	public static $property = array(
		'wbtype',
		'name',
		'caption',
		'x',
		'y',
		'width',
		'height',
		'mask',
		'multiline',
		'disabled',
		'readOnly',
		'align',
		'visible'
	);
	
	public function __construct() { 
		parent::__construct(array(
			'wbtype' => 'EditBox',
			'caption' => 'this is editbox',
			'x' => 0,
			'y' => 0,
			'width' => 100,
			'height' => 20,
			'multiline' => false,
			'mask' => false,		
			'readOnly' => false,		
		));
	}
	
	/**
	 * 컨트롤 그리기 
	 * 
	 * @param WBGraphics $graphics
	 */
	public function displayControl(WBGraphics $g) {

		$color = NOCOLOR;
		
		if ($this['disabled'] && $this['readOnly']) { 
			$color = FormControl::DISABLED;
		} else { 
			$color = FormControl::EDIT;
		}
		
		// draw editbox 

		$xstart = $this->getOption('x');
		$ystart = $this->getOption('y');
		$width = $this->getOption('width');
		$height = $this->getOption('height');
		$xend = $xstart + $width;
		$yend = $ystart + $height;
		$caption = $this['caption'];
	
		$g->rect($xstart, $ystart, $width, $height, $color, true);
		$g->line($xend - 2, $ystart, $xend - 2, $yend - 2, FormControl::EDITSHADE);
		$g->line($xstart, $yend - 2, $xend - 2, $yend - 2, FormControl::EDITSHADE);
		$g->line($xstart, $ystart, $xend - 2, $ystart, FormControl::SHADOW);
		$g->line($xstart, $ystart, $xstart, $yend - 2, FormControl::SHADOW);
		
		if($this['mask']) {
			$caption = str_repeat('*', strlen($caption));
		}
	
		if(strstr($caption, ',')) { 
			$title = str_replace(',', "\n", $caption);
		} else { 
			$title = str_repeat($caption . "\r\n", 20);
		}
		
		$font = ($this['disabled']) ? self::$disabledFont : self::$realFont ;
	
		if($this['multiline']) {
			$g->text($title, $xstart + 4, $ystart + 2, $width - 4, $height - 2, $font,  WBC_MULTILINE);
			
			// render scrollbar
			$scrollbar = new FormScrollBar();
			$scrollbar['caption'] = $caption;
			$scrollbar['x'] = $xstart + $width - 19;
			$scrollbar['y'] = $ystart + 1;
			$scrollbar['width'] = 18;
			$scrollbar['height'] = $height - 2;
			$scrollbar['disabled'] = $this['disabled'];
			$scrollbar['readOnly'] = $this['readOnly'];
			$scrollbar['multiline'] = $this['multiline'];
			
			$scrollbar->displayControl($g);
		} else {
			$g->text($title, $xstart + 4, $ystart + 2, $width - 4, $height - 2, $font, WBC_LEFT | WBC_TOP);
		}		

	}
	
	public function getProperty() { 
		return self::$property;
	}

}


?>